package net.hn.hnms.biz.plan.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.plan.request.ExecutionCostReq;
import net.hn.hnms.biz.plan.service.impl.ExecutionCostServiceImpl;
import net.hn.hnms.biz.plan.service.impl.ExecutionFootageOutputServiceImpl;
import net.hn.hnms.biz.plan.vo.ExecutionCostVO;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 生产成本计划执行
 *
 * @author zhaoyang
 * @date 2022-08-01
 */

@Api(value = "生产成本计划执行模块", tags = {"生产成本计划执行"})
@RestController
@RequestMapping("/execution/cost")
public class ExecutionCostController extends BaseController {


    @Autowired
    private ExecutionCostServiceImpl executionCostService;

    @Autowired
    private ExecutionFootageOutputServiceImpl executionFootageOutputService;

    /**
     * 新增生产成本计划执行
     */
    @ApiOperation("新增生产成本计划执行")
    @SaCheckPermission("execution:cost:add")
    @PostMapping("/add")
    @Log(title = "新增生产成本计划执行", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody ExecutionCostReq executionCost) {
        return toAjax(executionCostService.insert(executionCost));
    }

    /**
     * 删除生产成本计划执行
     */
    @ApiOperation("删除生产成本计划执行")
    @SaCheckPermission("execution:cost:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @DeleteMapping("delete")
    @Log(title = "删除生产成本计划执行", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        executionCostService.deleteBatch(idList);
        return R.ok();
    }

    /**
     * 修改生产成本计划执行
     */
    @ApiOperation("修改生产成本计划执行")
    @SaCheckPermission("execution:cost:update")
    @PutMapping("/update")
    @Log(title = "修改生产成本计划执行", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody ExecutionCostReq executionCost) {
        executionCostService.updateById(executionCost);
        return R.ok();
    }

    /**
     * 获取生产成本计划执行列表
     */
    @ApiOperation("获取生产成本计划执行分页列表")
//    @SaCheckPermission("execution:cost:page")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<ExecutionCostVO>> page(ExecutionCostReq executionCost, PageQuery pageQuery) {
        return R.ok(executionCostService.selectPageList(executionCost, pageQuery));
    }

    /**
     * 获取生产成本计划执行列表
     */
    @ApiOperation("获取生产成本计划执行列表")
//    @SaCheckPermission("execution:cost:list")
    @GetMapping("/list")
    public R<List<ExecutionCostVO>> list(ExecutionCostReq executionCost) {
        return R.ok(executionCostService.selectList(executionCost));
    }

    /**
     * 获取生产成本计划执行详情
     */
    @ApiOperation("获取生产成本计划执行详情")
//    @SaCheckPermission("execution:cost:list")
    @GetMapping("/{id}")
    public R<ExecutionCostVO> detail(@PathVariable("id") String id) {
        return R.ok(executionCostService.selectDetailById(id));
    }


    @ApiOperation("导出生产信息统计数据")
    @PostMapping("/exportProduction")
    @Log(title = "导出生产信息统计数据", businessType = BusinessType.EXPORT)
    @AutoSetMineCode
    public void exportProductionStatistics(HttpServletResponse response, String beginDate, String mineCode){
        executionFootageOutputService.exportProductionStatisticsData(response,beginDate,mineCode);
    }



}
